home *** CD-ROM | disk | FTP | other *** search
-
- /**************************************************************************
- EXAMPLE.C
-
- Written by: Eric Jorgensen (April, 1995)
-
- This code was written using Turbo C. It is intended to demonstrate the
- use of Varmint's Audio Tools and to provide a example code for program
- who wish to use VAT.
-
- This code is FREEWARE
-
- You are free to distribute without any restrictions as long as you
- charge no fee.
-
-
- **************************************************************************/
-
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include <io.h>
- //#include <alloc.h>
- #include "sound.h"
- #include <math.h>
- #include <time.h>
- #include "graph.h"
-
- #define getbit(x,y) ((x>>y) & 0x01)
- #define setbit(x,y) x = x & (0x01<<y)
- #define togbit(x,y) x = x ^ (0x01<<y)
-
- // function prototypes
- void fmdemo(void);
- void mididemo(void);
- void sb_intro(void);
- void dspdemo(void);
- void moddemo(void);
- void vsyncdemo(void);
- void introtext(void);
- void diagnostics(void);
- void debugoptions(void);
- void print_num(float i);
-
-
- //-------------------------- DATA and Globals --------------------
-
- // Instrument data
- char inst[9][11] =
- {
- { 0x03,0x01,0x00,0x00,0xF3,0xE4,0x64,0x35,0x00,0x01,0x00}, // Harpsichord
- { 0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x06,0x03,0x00}, // intro voice
- { 0x02,0x06,0x94,0x0A,0x80,0x80,0x00,0x00,0x00,0x00,0x00}, // intro voice
- { 0x00,0x04,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00},
- { 0x01,0x01,0x40,0x40,0x80,0x80,0x00,0x00,0x01,0x00,0x00},
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x01},
- { 0xA5,0xB1,0xD2,0x80,0x81,0xF1,0x03,0x05,0x00,0x00,0x02},
- { 0x72,0x62,0x1C,0x05,0x51,0x52,0x03,0x13,0x00,0x00,0x0E},
- { 0x11,0x01,0x8A,0x40,0xF1,0xF1,0x11,0xB3,0x00,0x00,0x06}};
-
- int vints[8] = {1,2,1,2,1,2,1,2}; // voice defs for introduction
- // Start/end frequencies for intro
- WORD startfreq[8] = {0xa000,0x6000,0xa000,0x2000,0x1000,0x9000,0xa000,0x6000};
- WORD endfreq[8] = {0x0800,0x2800,0x4800,0x6800,0x8800,0xa800,0xc800,0xe800};
-
- char *regname[11] = { // FM register name list
- "Amp mod/ vib/ eg type/ keyscale/ multiple 1",
- "Amp mod/ vib/ eg type/ keyscale/ multiple 2",
- "Key scale level / oper out level 1",
- "Key scale level / oper out level 2",
- "attack/decay rate 1",
- "attack/decay rate 2",
- "sustain level / release rate 1",
- "sustain level / release rate 2",
- "Feedback / Algorythm (oper 1&2)",
- "Wave Form Select (oper 1)",
- "Wave Form Select (oper 1)"
- };
-
- char *effect_primary[] = { // MOD command names
- "Arpeggio",
- "PortaM up",
- "PortaM down",
- "Porta NOTE",
- "Vibrato",
- "porta+vol",
- "Vib+vol",
- "Tremolo",
- "UNUSED",
- "Set offset",
- "Vol slide",
- "Postn Jmp",
- "Set Volume",
- "Pat Break",
- "special14",
- "Set Speed"};
- char *effect_secondary[] = {
- "Filter T/F",
- "Finesld up",
- "Finesld dn",
- "Gliss T/F",
- "Vibr WF",
- "Finetune WF",
- "Loop Pattrn",
- "Tremolo WF",
- "UNUSED",
- "Retrigger",
- "FineVolS up",
- "FineVolS Dn",
- "Cut Sample",
- "Delay Sampl",
- "Delay Pttrn",
- "Invert Loop"};
- // Patchmap to work on really
- // lame MIDI ouput devices.
- BYTE mypatchmap[16] = {0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,2};
-
- char hexchar[16] = {"0123456789ABCDEF"}; // hexidecimal character list
-
- SAMPLE *sound1,*sound2,*aha;
- unsigned long int l1=1,l2=1,laha=1;
- FILE *diagoutput= NULL;
- int mpu_checked = FALSE;
-
- /**************************************************************************
- void main()
-
- DESCRIPTION: Handles the main menu and sets things up
-
- **************************************************************************/
- void main(int argc,char *argv[])
- {
- int i= 0;
- char r = 0,twirl[6] = "|/-\\";
-
- // _setvideomode(_VRES16COLOR);
-
- if(argc>1) debugoptions();
-
- introtext();
- diagnostics();
-
- if(diagoutput) {
- fprintf(diagoutput,"DMA_bufferlen: %u\n",dma_bufferlen);
- fprintf(diagoutput,"Sample Rate: %u\n",sample_rate);
- fflush(diagoutput);
- }
-
- if(SB_Setup()) {
-
- if(diagoutput) {
- fprintf(diagoutput,"Post SB_setup settings: I:%d D:%d A:%X P:%X T:%d\n",intnr,dma_ch,io_addr,midi_port,card_id);
- fprintf(diagoutput,"DSP Version: %u.%u\n",dsp_vers>>8,dsp_vers&0xff);
- fflush(diagoutput);
- }
-
- Go_Varmint(); // Install Varmint's tools
- if(diagoutput) {
- fprintf(diagoutput,"Got past Go_Varmint.\n");
- fflush(diagoutput);
- }
-
- sound1 = loadwave("doink.wav",&l1); // Load up our sound effects
- sound2 = loadwave("wooeep.wav",&l2);
- aha = loadwave("aha.wav",&laha);
- if(!sound1 || !sound2 || !aha) {
- printf("ERROR loading sounds: (%d,%d)\n",sound1,sound2);
- exit(0);
- }
-
- if(diagoutput) {
- fprintf(diagoutput,"Got past loadwave.\n");
- fflush(diagoutput);
- }
-
- sb_intro(); // Get their attention
-
- if(diagoutput) {
- fprintf(diagoutput,"Got past sb_intro.\n");
- fflush(diagoutput);
- fclose(diagoutput);
- }
-
- while(kbhit()) getch();
- while(r != 'Q') { // Main input loop
-
- _clearscreen(_GCLEARSCREEN); // CLear screen and draw menu
- _settextcolor(8);//DARKGRAY);
- //cprintf("far core left %lu",farcoreleft());
- _settextcolor(7);
- //textcolor(WHITE);
- _settextposition(8,20);
- // _settextposition(20,8);
- _outtext("Demonstration: Varmint's Audio Tools\n\n");
- _settextcolor(14);
- // textcolor(YELLOW);
- _settextposition(10,30);
- _outtext("1) FM voice");
- _settextposition(11,30);
- _outtext("2) MIDI");
- _settextposition(12,30);
- _outtext("3) Sounds");
- _settextposition(13,30);
- _outtext("4) MOD");
- _settextposition(14,30);
- // _outtext("5) VSYNC");
- // _settextposition(20,30);
- _outtext("Q) quit");
-
- while(!kbhit()) { // Draw a twirling thing while
- // we wait for a keypress.
- _settextposition(16,35);
- _outtext(" ");
- cprintf("%c",twirl[++i%4]);
- _settextposition(14,30);
- msdelay(50);
- }
- r = toupper(getch()); // grab some input
-
- if(r == '1') fmdemo(); // Do something with it
- else if(r == '2') {
- mididemo();
- }
- else if(r == '3') {
- dspdemo();
- }
- else if(r == '4') {
- moddemo();
- }
- // else if(r == '5') {
- // vsyncdemo();
- // }
- }
- Dropdead_Varmint(); // Release Varmint's interrupt
- }
- else {
- printf("SB_Setup returned this error: %s \n",errname[sberr]);
- if(diagoutput) {
- fprintf(diagoutput,"Failed SB_setup.\n");
- fprintf(diagoutput,"SB_Setup returned this error: %s \n",errname[sberr]);
- }
- }
-
- }
-
-
- /**************************************************************************
- void vsyncdemo(void)
-
- DESCRIPTION: The demonstrates the use of VarmintVSync() for animation
-
- **************************************************************************/
- void vsyncdemo(void)
- {
- int x=5;
- char *drawme = {"HONIG"};
- char r=0;
-
- _clearscreen(_GCLEARSCREEN);
-
- vsync_toolong = 4; // This is the number of varmint ticks
- // that can happen between vertical
- // retraces. (Assuming that the
- // Monitor is refreshed at aroun 65 hz)
-
- // Display intro text.
- _settextposition(2,16);
- _outtext("VAT's mixing kernel can interfere with ordinary functions that\n");
- _outtext("monitor the vertical retrace bit, causing `jerky' animation.\n");
- _outtext("With sync checking off, the animation above will jerk badly\n");
- _outtext("when you play sounds. (Make sure any background MOD music is\n");
- _outtext("off, or you will not be able to see the difference.)\n\n");
- _outtext("Press 1,2, or 3 to play sounds.\n");
- _outtext("Press <space> to toggle sync checking, 'Q' to quit");
-
- _settextposition(60,23); // Display status of sync_on
- _settextcolor(14);
- // textcolor(YELLOW);
- if(sync_on) _outtext("SYNC ON ");
- else _outtext("SYNC OFF ");
-
- while(toupper(r) != 'Q') { // Input/animation loop
- if(kbhit()) { // Key stroke waiting?
- r = getch();
- if(r == ' ') { // toggle sync checking
- sync_on ^= TRUE;
- _settextposition(23,60);
- if(sync_on) _outtext("SYNC ON ");
- else _outtext("SYNC OFF ");
- } // Play sounds
- else if(r == '1') playsound(sound1,l1);
- else if(r == '2') playsound(sound2,l2);
- else if(r == '3') playsound(aha,laha);
- }
-
- // Animate a little bit of text
- _settextposition(4,x);
- printf(" ");
-
- x++;
- if(x>74) x= 1;
-
- _settextposition(4,x);
- printf("%s",drawme);
-
- VarmintVSync(); // Wait for a retrace to finish
-
- }
- }
-
-
- /**************************************************************************
- moddemo(void)
-
- DESCRIPTION: Demo for playing MOD files
-
- **************************************************************************/
- void moddemo(void)
- {
- char twirl[6] = "|/-\\";
- char str[80];
-
- int i,playme = 0;
- int k;
- char r=0;
- static MOD *mymod = NULL;
- DWORD count=0,total=0;
- double oh;
-
- _clearscreen(_GCLEARSCREEN); // Clear the screen
-
- if(!mymod) { // Load the mod on first entry
- mymod = loadmod("noname.mod");
- if(!mymod) {
- _outtext("Unable to load MOD file: noname.mod");
- msdelay(2000);
- return;
- }
- mod_data = mymod; // Set initial mod parameters
- mod_reset = TRUE;
- }
-
- DSP_overhead = 1; // Turn on overhead checking
- _settextcolor(5);
- // textcolor(MAGENTA);
-
- _settextposition(2,4);
- _outtext("MOD demo menu"); // Draw the menu
- _settextcolor(3);
- // textcolor(CYAN);
- _settextposition(4,4);
- _outtext("V,v - Change music volume");
- _settextposition(5,4);
- _outtext("T,t - Change music tempo");
- _settextposition(6,4);
- _outtext("M - Music On/off toggle");
- _settextposition(7,4);
- _outtext("R - Reset MOD");
- _settextposition(8,4);
- _outtext("1-4 - Toggle Channels on/off");
- _settextposition(9,4);
- _outtext("S - Select Current sample");
- _settextposition(10,4);
- _outtext("<Space> - Play Current sample");
- _settextposition(12,4);
- _outtext("Q - Quit");
-
- _settextposition(16,2);
- _outtext("MOD Title: ");
- _outtext(mymod->title);
- // printf("MOD Title: %s ",mymod->title);
-
-
- while(toupper(r) != 'Q') { // Input Loop
-
- if(kbhit()) { // Keyboard have input?
- _settextposition(16,35);
- _outtext(" ");
- _outtext((char*)twirl[++i%4]);
- // cprintf("%c",twirl[++i%4]);
-
- r = getch(); // Grab the key
- if(r == 'm')
- // This is a band aid fix for a bug with the MOD funciton
- if(mod_on==FALSE)
- {
- mod_reset=TRUE;
- mod_on=TRUE;
- }
- else
- mod_on ^= TRUE; // Mod on/off
- else if(r == 'V') { // Volume louder
- mod_volume--;
- if(mod_volume < 1) mod_volume = 1;
- }
- else if(r == 'v') { // Volume softer
- mod_volume++;
- if(mod_volume > 16) mod_volume = 16;
- }
- else if(r == 'T') { // Tempo faster
- mod_bytespertick-=10;
- if(mod_bytespertick < dma_bufferlen) mod_bytespertick = dma_bufferlen;
- }
- else if(r == 't') { // Tempo slower
- mod_bytespertick+=10;
- if(mod_bytespertick > 10000) mod_bytespertick = 10000;
- }
- else if(r == 'r') mod_reset = TRUE; // Mod reset
- else if(r == '1') channel_select[0] ^= 1; // Turn channels on/off
- else if(r == '2') channel_select[1] ^= 1;
- else if(r == '3') channel_select[2] ^= 1;
- else if(r == '4') channel_select[3] ^= 1;
- else if(r == 's') { // Cycle through samples
- playme++;
- while(!mymod->sdata[playme]) {
- playme++;
- if(playme>31) playme = 0;
- }
- } // Play current sample
- else if(r == ' ') playsound(mymod->sdata[playme],mymod->slength[playme]);
- }
-
- k = vclock;
- while(k == vclock)
-
- for(i = 0; i < 4; i++) {
-
- // Darken unselected channels
- if(channel_select[i]) _settextcolor(14);
- else _settextcolor(6);
-
- _settextposition(18+i,2); // Print the label
- // cprintf("CHANNEL%d:",i+1);
- _outtext("CHANNEL");
- print_num((i+1));
- _outtext(":");
-
- _settextposition(18+i,16); // Print sample number
- if(chan[i].position <= chan[i].end) {
- print_num(chan[i].sample_number);
- // cprintf("%d",chan[i].sample_number);
- }
- else _outtext(" ");
-
- _settextposition(18+i,22);
- if(chan[i].position <= chan[i].end) {
- if(chan[i].effect != 14)
- // cprintf("%s ",effect_primary[chan[i].effect]);
- {
- _outtext(effect_primary[chan[i].effect]);
- _outtext(" ");
- }
- else
- // cprintf("%s (E) ",effect_secondary[chan[i].x]);
- {
- _outtext(effect_secondary[chan[i].x]);
- _outtext(" (E) ");
- }
- }
- else _outtext(" ");
-
- _settextposition(18+i,42);
- print_num(chan[i].period);
- // cprintf("%d",chan[i].period);
-
- _settextposition(18+i,52);
- print_num(chan[i].volume);
- // cprintf("%d",chan[i].volume);
- }
-
- _settextposition(4,40); // SHow current volume
- // printf("VOLUME BYTE: %d ",mod_volume);
- _outtext("VOLUME BYTE: ");
- print_num(mod_volume);
-
- _settextposition(5,40); // Show the tempo
- // printf("TEMPO: %d ",mod_bytespertick);
- _outtext("TEMPO: ");
- print_num(mod_bytespertick);
-
- _settextposition(6,40); // Show playing status
- if(mod_on) _outtext("MOD on ");
- else _outtext("MOD off ");
-
- _settextposition(7,40); // Print channel name/command info
- _outtext("Tick: ");
- print_num(mod_currenttick);
- _outtext(" Table position: ");
- print_num(mod_tablepos);
- // printf("Tick: %d Table position: %d ",mod_currenttick,mod_tablepos);
-
- _settextposition(10,40);
- // printf("Current sample: %d (%s) ",playme+1,mymod->sample_name[playme]);
- _outtext("Current sample: ");
- print_num(playme+1);
- _outtext("(");
- _outtext(mymod->sample_name[playme]);
- _outtext(") ");
- count++;
- total+=DSP_overhead;
- if(count == 20) {
- oh = (total * 0.9218)/(count * dma_bufferlen) * sample_rate/11000.0;
- _settextposition(23,4);
- sprintf(str,"CPU Overhead: %.2lf%% ",oh);
- _outtext(str);
- total = 0;
- count = 0;
- }
- }
-
- }
-
- void print_num(float i)
- {
- char *str;
- double num;
- int dec, sign, ndig = 1;
-
- /* a regular number */
- str = fcvt(i, ndig, &dec, &sign);
- _outtext(str);
- }
-
- /**************************************************************************
- void dspdemo(void)
-
- DESCRIPTION: Plays sound effects with Varmint's Audio Tools
-
- **************************************************************************/
- void dspdemo(void)
- {
- char r = 0;
- DWORD tot = 0,num = 0,vc;
- double oh;
- char *str;
-
- int dec, sign, ndig = 5;
-
-
- DSP_overhead = 1; // turn on overhead checking
-
- _clearscreen(_GCLEARSCREEN); // Clear screen and draw a menu
- _settextcolor(2);
- // textcolor(GREEN);
- _settextposition(8,25);
- _outtext("Sound effects demo menu");
- _settextcolor(14);
- // textcolor(YELLOW);
- _settextposition(10,25);
- _outtext("1,2,3 - Play a sound effect");
- _settextposition(11,25);
- _outtext("Q - Quit");
-
- _settextposition(1,1);
- _outtext("CPU OVERHEAD: \nSAMPLES IN QUEUE: ");
- while(toupper(r) != 'Q') { // input loop
- while(!kbhit()) { // Wait for keystroke
- vc = vclock;
- // while(vc == vclock); // wait for the interrupt
-
- tot+= DSP_overhead; // take an average every 40 interrupts
- num++;
- if(num == 40) {
- oh = (tot * 0.9218)/(num * dma_bufferlen)*sample_rate/11000;
-
- // str = fcvt(oh, ndig, &dec, &sign);
- _settextposition(1,15);
- // _outtext(str);
- print_num(oh);
- // printf("%2.2lf%% ",oh); // Show overhead
- _settextposition(2,19);
- str = fcvt(sounds_in_queue, 1, &dec, &sign);
-
- // printf("%d \n",sounds_in_queue); // Show # sounds playing
- _outtext(str);
- _outtext(" ");
- // print_num(sounds_in_queue);
- num = 0;
- tot = 0;
- }
- }
- r = getch(); // Get keystroke and act accordingly
- if(r == '1') playsound(sound1,l1);
- else if(r == '2') playsound(sound2,l2);
- else if(r == '3') playsound(aha,laha);
- }
- }
-
- /**************************************************************************
- void sb_intro(void)
-
- DESCRIPTION: Cool introduction sith sound blaster music and sounds
-
- **************************************************************************/
- void sb_intro(void)
- {
- int i,j;
- double fr;
- WORD f;
-
- _clearscreen(_GCLEARSCREEN);
- _settextposition(1,1);
- printf("Varmint's Audio Tools (Version: %s)",VAT_VERSION);
- msdelay(500);
-
- // Cool introduction
- // while(kbhit());
-
- FM_Reset();
-
- for(i = 0; i < 2; i++) {
- playsound(aha,laha); // Digital intro speach
- msdelay(15);
- }
-
- for(i = 0; i < 8; i++) { // initialize music voices
- FM_SetVoice(i,inst[vints[i]]);
- FM_SetFreq(i,startfreq[i]);
- FM_SetVol(i,0x00);
- FM_KeyOn(i);
- }
- for(i = 0; i < 1000; i+= 1) { // morph a big chord
- fr = i/1000.0;
- for(j = 0; j < 8; j++) {
- _settextposition(10,j*10+1);
- f = startfreq[j]+((double)endfreq[j]-(double)startfreq[j]) * fr;
- cprintf("%X ",f);
- FM_SetFreq(j,f);
- FM_SetVol(j,fr*0x3f );
- FM_KeyOn(j);
- }
- msdelay(5);
- if(kbhit()) i = 1000;
- }
-
- if(!kbhit()) {
- for(i = 0; i < 8; i++) { // Make sure all the notes are right
- FM_SetFreq(i,endfreq[i]);
- FM_KeyOn(i);
- }
-
- for(i = 0x3f ; i >= 0; i-= 1) { // quiet down slowly
- for(j = 0; j < 8; j++) {
- FM_SetVol(j,i);
- }
- msdelay(i*2+40);
- if(kbhit() & i) i = 1;
- }
- }
-
- for(i = 0; i < 9; i++) { // Silence them all
- FM_SetVol(i,0); // volume off
- FM_SetVoice(i,inst[0]); // this instrument has a decay, so it
- // gets all the way quiet
- FM_SetFreq(i,1); // Low freq = quiet
- }
-
- }
- /**************************************************************************
- void mididemo(void)
-
- DESCRIPTION: Example function that loads and "plays" a midi file
-
- **************************************************************************/
- void mididemo(void)
- {
- int i,err;
- char errstring[256],r=0;
- char str[80];
- static MIDI *bach = NULL;
-
- midi_patchmap = mypatchmap;
-
- _clearscreen(_GCLEARSCREEN); // clear screen
-
- FM_Reset();
-
- for(i = 0 ; i < 9; i++) {
- FM_SetVol(i,0);
- FM_SetVoice ( i,inst[0]) ; // initialize voice
- }
- if(!bach) {
- // load a midi file
- err = ReadMidi("cannon_d.mid",&bach,(char *)errstring);
- if(err) {
- printf("MIDI read ERROR: %s\n",errstring);
- printf("Exit?\n");
- r = getch();
- if(r != 'n') return;
- }
- midi_data = bach;
- midi_reset = TRUE;
- }
-
- //printf("FORMAT: %d TRACKS: %d DIVISION: %d\n",
- // bach->format,bach->num_tracks,bach->divisions);
-
- _settextcolor(5);
- // textcolor(MAGENTA);
- _settextposition(2,30);
- _outtext("MIDI demo menu");
-
- _settextcolor(3);
- // textcolor(CYAN);
- _settextposition(4,30);
- _outtext("V,v - Change music volume");
- _settextposition(5,30);
- _outtext("T,t - Change music tempo");
- _settextposition(6,30);
- _outtext("M - Toggle music: ");
- _settextcolor(2);
- if(midi_on) _outtext("ON ");
- else _outtext("OFF ");
- _settextcolor(3);
- _settextposition(7,30);
- _outtext("R - Reset Music");
- _settextposition(8,30);
- _outtext("F - Toggle FM output: ");
- _settextcolor(2);
- if(midi_fmout) _outtext("ON ");
- else _outtext("OFF ");
- _settextcolor(3);
- _settextposition(9,30);
- _outtext("U - Toggle MPU output: ");
- _settextcolor(2);
- if(midi_mpuout) _outtext("ON ");
- else _outtext("OFF ");
- _settextcolor(3);
- _settextposition(10,30);
-
- _outtext("P - Set MPU-401 MIDI port");
-
- _settextposition(13,30);
-
- _outtext("Q - Quit");
-
- if(!mpu_available && mpu_checked) {
- _settextposition(20,1);
- _outtext("Current MPU-401 midi port is invalid.");
- }
-
-
- while(toupper(r) != 'Q') { // MAIN LOOP
- _settextposition(14,30); // print temppo and volume stats
- _settextcolor(15);
- // textcolor(WHITE);
- // cprintf("Music Volume: %d ",music_volume);
- _outtext("Music Volume: ");
- print_num(music_volume);
-
- _settextposition(15,30);
- sprintf(str,"Music Tempo: %.2f ",midi_usertempo);
- _outtext(str);
-
- // print_num(midi_usertempo);
-
- while(!kbhit()) { // handle the keyboard
- if(mpu_checked) {
- _settextposition(4,1); // check midi status while we wait
- if(mpu_timeout < 1000) _outtext("MPU status: OK! ");
- else _outtext("MPU status: Timing out ");
- _settextposition(5,1);
- printf("Current port: %X ",midi_port);
- }
- }
- r = getch(); // get keystroke
-
- if(r == 'V') { // Handle keystrokes
- music_volume++;
- if(music_volume > 0x3f) music_volume = 0x3f;
- }
- else if(r == 'v') {
- if(music_volume > 0) music_volume--;
- }
- else if(toupper(r) == 'R') {
- midi_reset = TRUE;
- }
- else if(r == 'T') {
- midi_usertempo *= 1.02;
- if(midi_usertempo > 10.0) midi_usertempo = 10.0;
- }
- else if(r == 't') {
- midi_usertempo *= 0.98;
- if(midi_usertempo < 0.1) midi_usertempo = 0.1;
- }
- else if(toupper(r) == 'M') {
- midi_on ^= TRUE;
- _settextposition(6,50);
- _settextcolor(2);
- if(midi_on) _outtext("ON ");
- else _outtext("OFF ");
- _settextcolor(3);
- }
- else if(toupper(r) == 'P') { // Get a new MPU port address
- _settextposition(1,19);
- printf("Enter new port address in hex values [%x]: ",midi_port);
- gets(errstring);
- if(strlen(errstring)) sscanf(errstring,"%x",&midi_port);
-
- // check for accidents
- if(midi_port < 0x200 || midi_port > 0x360) midi_port = 0x330;
- mpu_available = MPU_Reset();
- _settextposition(20,1);
- if(!mpu_available) _outtext("Current MPU-401 midi port is invalid.");
- else printf(" ");
- _settextposition(19,1);
- _outtext(" ");
- mpu_checked = TRUE;
- }
- else if(toupper(r) == 'F') { // Toggle output
- midi_fmout ^= TRUE;
- _settextcolor(3);
- // textcolor(CYAN);
- _settextposition(8,54);
- _settextcolor(2);
- if(midi_fmout) _outtext("ON ");
- else _outtext("OFF ");
- _settextcolor(3);
- }
- else if(toupper(r) == 'U' && mpu_available) { // Toggle output
- midi_mpuout ^= TRUE;
- _settextcolor(3);
- // textcolor(CYAN);
- _settextposition(9,55);
- _settextcolor(2);
- if(midi_mpuout) _outtext("ON ");
- else _outtext("OFF ");
- _settextcolor(3);
- }
- }
- }
-
-
- /**************************************************************************
- void bitprint(char byte)
-
- DESCRIPTION: Prints individual bits and then a HEX value
-
- **************************************************************************/
- void bitprint(unsigned char byte)
- {
- int i;
- char str[90];
- _outtext(" ");
- // cprintf(" ");
- // go through bits
- for(i = 7; i >= 0; i--) {
- if(getbit(byte,i)) { // 1's are yellow
- _settextcolor(14);
- // textcolor(YELLOW);
- _outtext("1");
- }
- else { // 0's are dark grey
- _settextcolor(8);
- // textcolor(DARKGRAY);
- _outtext("0");
- // cprintf("0");
- }
- }
- _settextcolor(9);
- // textcolor(LIGHTBLUE); // print the hex value
- sprintf(str," %c%c",hexchar[byte/16],hexchar[byte%16]);
-
- _outtext(str);
- _settextcolor(7);
- // textcolor(WHITE);
- }
-
-
-
- /**************************************************************************
- void fmdemo()
-
- DESCRIPTION: Allows th user to mess around with instruments and
- play a few notes.
-
-
- **************************************************************************/
- void fmdemo(void)
- {
- unsigned int i,cx,cy,voice=0,instrument = 0;
- int drawvoice = 1,rythm = 0;
- char r = 0;
-
- _clearscreen(_GCLEARSCREEN); // clear screen
- _settextposition(1,1);
- _outtext("FM demonstration screen");
- // printf("FM demonstration screen");
- FM_Reset();
- for(i = 0; i < 9; i++) FM_KeyOff(i);
-
- _settextposition(16,1);
- _outtext("IJKL = cursor movement\r\n");
- _outtext("<space> = toggle bit\r\n");
- _outtext("numbers = play notes\r\n");
- _outtext("v = change voice\r\n");
- _outtext("n = Change instrument\r\n");
- _outtext("r = toggle rythm mode\r\n");
- _outtext("q = quit");
-
- _settextcursor(0x0007);
-
- for( i = 0; i < 8; i++) { // initialize voices
- FM_SetVoice ( i,inst[instrument]) ;
- FM_SetVol(i,0);
- }
-
- cx = 54;cy = 5; // init cursor position
-
- for(i = 0; i < 11; i++) { // print register names
- _settextposition(i+5,50-strlen(regname[i]));
- _settextcolor(5);
- // textcolor(MAGENTA);
- // cprintf("%s",regname[i]);
- _outtext(regname[i]);
- }
-
-
- while(r != 'Q') { // main input loop
- if(drawvoice) {
- for(i = 0; i < 11; i++) { // display instrument data
- _settextposition(i+5,52);
- bitprint(inst[instrument][i]);
- }
- for(i = 0; i < 9; i++) {
- FM_SetVoice ( i,inst[instrument]) ; // initialize new voice
- }
- drawvoice = 0;
- _settextcolor(8);
- // textcolor(LIGHTGRAY);
- _settextposition(4,52);
- _outtext("Instrument #");
- // _outtext(ecvt(instrument));
- // cprintf("Instrument #%d ",instrument);
- print_num(instrument);
- }
-
- _settextposition(cy,cx); // put cursor in right spot
-
- while(!kbhit()){
- }
-
- r = toupper(getch());
- if(r >= '0' && r <= '9') {
- FM_KeyOff(voice);
- FM_SetVoice(voice,inst[instrument]);
- FM_SetNote ( voice, (r-'0'+3) * 8) ;
- FM_SetVol(voice,music_volume);
- FM_KeyOn(voice);
- }
- else if(r == 'I') { // i,j,k,l = cursor movement
- cy = cy -1;
- if(cy<5) cy = 5;
- }
- else if(r == 'K') {
- cy = cy +1;
- if(cy >15) cy = 15;
- }
- else if(r == 'J') {
- cx = cx -1;
- if(cx<54) cx = 54;
- }
- else if(r == 'L') {
- cx = cx +1;
- if(cx>61) cx = 61;
- }
- else if(r == ' ') { // space = toggle bit
- togbit(inst[instrument][cy-5],(7-(cx-54)));
- drawvoice = 1;
- }
- else if(r == 'N') { // I = change instrument
- instrument++;
- if(instrument > 8) instrument = 0;
- drawvoice = 1;
- }
- else if(r == 'R') { // r = toggle rythm mode
- if(rythm) rythm = 0;
- else rythm = 1;
- FM_RythmMode(rythm); // do it
- FM_RythmOn(FM_HIHAT);
- _settextposition(2,1); // tell the user
- if(rythm) _outtext("Rythm Mode ON (voices 6,7,8 only) ");
- else _outtext("Rythm Mode OFF ");
- }
- else if(r == 'V') { // v = change voice
- FM_KeyOff(voice);
- FM_SetVol(voice,0);
- voice ++;
- if(voice > 8) voice = 0;
- _settextposition(1,3);
- cprintf("Voice: %d ",voice);
- }
- else if(r == 'W') { // Frequency ramp
- for(i = 0; i < 0xf000; i+= 0x10) {
- FM_SetFreq(voice,i);
- FM_KeyOn(voice);
- msdelay(5);
- }
- }
-
-
- }
- for(i = 0; i < 9; i++) {
- FM_SetVol(i,0);
- }
-
- }
-
-
-
- /**************************************************************************
- void introtext(void)
-
- DESCRIPTION: Display introduction text for the user.
-
-
- **************************************************************************/
- void introtext(void)
- {
- _clearscreen(_GCLEARSCREEN);
- _settextposition(1,1);
- _outtext("Varmint's Audio Tools for Watcom (Version: 0.51) Demonstration\n");
-
- // ,VAT_VERSION);
- // printf("\n");
- _settextcolor(14);
- // textcolor(YELLOW);
- _settextposition(3,1);
- _outtext("Please edit the file survey.txt and return it to:\r\n");
- _outtext("\n");
- _outtext(" gavinb@ix.netcom.com\n");
- _outtext("\n");
- _outtext("This is the first version of Varmit Audio Tools to be\n");
- _outtext("ported to Watcom Cv9.5. Use it with extreme caution\n");
- _outtext("and don't leave any food out for the rats.\n");
-
- _settextcolor(15);
- _outtext("\n\n");
- _outtext("To compile you must use the /zu command line option\n");
- _outtext("wcl386 /zu sound.c myprog.c\n");
- _outtext("\n\n");
-
- _settextcolor(14);
- _outtext("If you have not seen the real mode version of this program\n");
- _outtext("I recommend you check that version out.\n");
-
- _outtext("\n");
- _outtext("\n\n -Brian Gavin\n");
-
- _outtext("\n\nPlease press the space bar to continue...");
-
- while(!kbhit());
- getch();
- }
-
-
- /**************************************************************************
- void diagnostics(void)
-
- DESCRIPTION: This prepares survey.txt to receive diagnostic information
- and writes a few introductory things in that file.
-
- **************************************************************************/
- void diagnostics(void)
- {
- char *e;
- int i,j,k;
- DWORD t;
-
- diagoutput = fopen("survey.txt","w"); // Open survey file
- if(!diagoutput) return;
-
- _outtext("\nTesting and recording system configuration.\n");
- // Write the survey
- fprintf(diagoutput,"Survey for Varmint's Audio tools.\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"Watcom Cv9.5 port \n");
- fprintf(diagoutput,"Please email the completed survey to gavinb@ix.netcom.com\n");
- fprintf(diagoutput,"-----------------------------------------------------------------------------\n");
- fprintf(diagoutput,"VERSION %s (beta)\n",VAT_VERSION);
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"1) What's your name and email address?\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"2) How did you hear about Varmint's Audio tools and where did you find\n");
- fprintf(diagoutput," this copy?\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"3) Did the demo work on your computer? If not, please describe what happened.\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"4) Have you tried earlier versions of VAT? What versions? Did the demos work?\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"5) Have you been able to use VAT in your own programs? What features made\n");
- fprintf(diagoutput," it easy or difficult to do so?\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"6) Please describe your computer system:\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput," CPU (eg: 386,486,Pentium):\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput," Internal clock speed (eg:66Mhz):\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput," Operating system(eg: DOS/Windows, OS/2):\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput," Sound card (eg: PAS16, GUS, SB16):\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"\n");
- fprintf(diagoutput,"7) Please add any additional praise or chastisement of Varmint's Audio Tools:\n");
-
- // Print some autodiag info
- fprintf(diagoutput,"\n---------- AUTO DIAGNOSTIC INFORMATION ---------\n");
- fprintf(diagoutput,"Everything below here was written automatically by\n");
- fprintf(diagoutput,"the VAT demo. Please do not delete these lines.\n");
- fprintf(diagoutput,"-------------------------------------------------\n\n");
-
- e = getenv("BLASTER"); // Record BLASTER variable
- if(e) fprintf(diagoutput,"BLASTER env variable: %s\n",e);
-
- t = clock(); // measure system performance
- for(i = 0; i < 1000; i++) {
- for(j = 0; j < 1000; j++ ) {
- k = i * j;
- }
- }
- t = clock()-t;
-
- fprintf(diagoutput,"Integer speed rating: %lu\n",t);
-
- // Check available memory
- // fprintf(diagoutput,"Core left: %lu\n",farcoreleft());
- fflush(diagoutput);
- }
-
-
- /**************************************************************************
- void debugoptions(void)
-
- DESCRIPTION: Allows the user to set certain debug options. These debug
- options will eventually be removed from the code when it
- is debugged.
-
- **************************************************************************/
- void debugoptions(void)
- {
- char r = 0;
-
-
- _clearscreen(_GCLEARSCREEN);
- printf("VAT debug options\n");
-
- _settextcolor(9);
- //textcolor(LIGHTBLUE);
-
- _settextposition(10,5);
- cprintf("1) Set Anitistatic byte");
- _settextposition(5,5);
- if(debug_antistatic) printf("ON");
- else printf("OFF");
-
- _settextposition(10,6);
- cprintf("2) Disable interrupts in mixing Kernel");
- _settextposition(5,6);
- if(debug_intdisable) printf("ON");
- else printf("OFF");
-
- _settextposition(5,20);
- printf("Press a number to toggle an option, or <space> to continue.");
-
- while(r != ' ') {
- r = toupper(getch());
- if(r == '1') {
- debug_antistatic ^= TRUE;
- _settextposition(5,5);
- if(debug_antistatic) printf("ON ");
- else printf("OFF ");
- }
- else if(r == '2') {
- debug_intdisable ^= TRUE;
- _settextposition(5,6);
- if(debug_intdisable) printf("ON ");
- else printf("OFF ");
- }
- }
-
- }
-
-
-
-